import Vue from 'vue'
import Router from 'vue-router'
import {isLoginIn}  from './auth'
Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('./views/Login.vue')
    },
    {
      path: '/chat',
      name: 'chat',
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () => import(/* webpackChunkName: "about" */ './views/Chat.vue'),
      beforeEnter: ((to, from, next) => {
          if (isLoginIn()){
            next();
          }else {
            next('/login')
          }
      })
    }
  ]
})
